<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        li {
            margin-bottom: 10px;
            background-color: pink;
            display: flex;
            justify-content: space-between;
            width: 300px;
        }
    </style>
</head>
<script src="../../../day6jquery/jquery3.5.min.js"></script>
<body>
    <textarea></textarea>
    <button>添加</button>
    <ul>

    </ul>
    <script>
        let btn = document.querySelector('button');
        let text = document.querySelector('textarea');
        let ul = document.querySelector('ul');
        btn.onclick = function(){
            if(text.value == ''){
                alert('请输入内容')
            }else{
                let li = document.createElement('li');
            li.innerHTML = text.value+'<button  id="dele">删除</button>'
            text.value=''
            ul.insertBefore(li,ul.children[0]);
            let dele = document.querySelectorAll('#dele');
            
            for(var i = 0; i< dele.length;i++){
                dele[i].onclick = function(){
                ul.removeChild(this.parentNode)
            }
            }
           
            }
        }
    </script>
</body>
</html>